﻿
var fullscreen_element = document.getElementById('eve-content');
var fullscreen_button = document.getElementById('eve-fullscreen-btn');
var exit_fullscreen_button = document.getElementById('eve-exit-fullscreen-btn');

fullscreen_button.addEventListener('click', function () {
    $(this).css("display", "none");
    $(exit_fullscreen_button).css("display", "inline-block");
    launchFullScreen(fullscreen_element);
}, false);
exit_fullscreen_button.addEventListener('click', function () {
    $(this).css("display", "none");
    $(fullscreen_button).css("display", "inline-block");
    cancelFullscreen(fullscreen_element);
}, false);
function launchFullScreen(element) {
    if (element.requestFullScreen) {
        element.requestFullScreen();
    } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    } else if (element.webkitRequestFullScreen) {
        element.webkitRequestFullScreen();
    } else if (element.msRequestFullScreen) {
        element.msRequestFullScreen();
    }
}
function cancelFullscreen() {
    if (document.cancelFullScreen) {
        document.cancelFullScreen();
    } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    } else if (document.webkitCancelFullScreen) {
        document.webkitCancelFullScreen();
    }
}

var totalquestion;
var totalanswered;
var soundeffect = document.getElementById("eve-center-game-audio");
var answereffect = document.getElementById("eve-center-game-answer-effect");
var soundsrc, effectsrc;
function start_game(gamename) {
    var event_id = document.getElementById("event_id").innerHTML;
    var question = 0;
    var type = 0;
    var status = 0;
    if (gamename == "dhbc") {
        type = 1;
    }
    if (gamename == "tttn") {
        type = 2;
    }
    if (gamename == "xvvtlch") {
        type = 3;
    }
    if (gamename == "gdoc") {
        type = 4;
    }

    var level = document.getElementById("player_level").innerHTML;
    if (level == "7") {
        open_event();
        document.getElementById("question_present_type").innerHTML = type;
        send_server_question(type, question, status, 0);
    }
    effectsrc = "/Content/effect/startquestion.mp3";
    answereffect.src = effectsrc;
    answereffect.play();
    totalquestion = $("#" + gamename).find(".eve-total-question").html();
    totalanswered = 0;
    $(".eve-team-waiting-text").hide();
    $('.eve-ready-text').hide();
    $(".eve-intro-time-circle-box").show();
    $(".eve-intro-time-circle").circletimer({
        onComplete: function () {
            $(".eve-center").removeClass("w3-threequarter").addClass("w3-half");
            $(".eve-left").animate({ "width": "toggle" }, "500");
            $(".eve-rule").animate({ "height": "toggle" }, "500");
            $(".eve-score").animate({ "height": "toggle" }, "500");
            $(".eve-team").css("height", "52.8%");
            $('.eve-ready').hide();
            $(".eve-center-header b").html($("#" + gamename).find(".eve-game-name").html());
            $(".eve-rule").find("#rule-" + gamename).show();
            $(".eve-score").find("#score-" + gamename).show();
            $(".eve-team-control-option").show();
            $("#" + gamename).show();
            $(".eve-intro-video").detach();
            $(".eve-center-content").show();
            soundeffect.pause();
        },
        onUpdate: function (elapsed) {
            $(".eve-intro-time-circle-box").find(".eve-time-remain-number").html(parseInt((parseInt($(".eve-seconds-number").html()) * 1000 - Math.round(elapsed)) / 1000) + 1);
        },
        timeout: parseInt($(".eve-seconds-number").html()) * 1000
    }).circletimer("start");
    soundsrc = "/Content/effect/countdownclock5min.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
}
function start_question(gamename) {
    document.getElementById("question_checked").innerHTML = 0;
    effectsrc = "/Content/effect/startquestion.mp3";
    answereffect.src = effectsrc;
    answereffect.play();
    if (gamename == "dhbc" || gamename == "tttn") {
        if (gamename == "dhbc") {
            $("#" + gamename).carousel("next");
            var level = document.getElementById("player_level").innerHTML;
            if (level == "7") {
                send_server_question(1, 1, 0, 0);
                document.getElementById("question_present_id").innerHTML = 1;
                document.getElementById("question_server_type").innerHTML = 1;
            }
            $(".eve-team-control-send-btn").removeAttr("disabled").attr("onclick", "team_control_send('" + gamename + "',this)");
            $(".eve-game-time-circle-box").show();
            $(".eve-game-time-circle").circletimer({
                onComplete: function () {
                    var event_id = document.getElementById("event_id").innerHTML;
                    var type = document.getElementById("question_present_type").innerHTML;
                    var question = document.getElementById("question_present_id").innerHTML;
                    var xhttp;
                    xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                            document.getElementById("indexof-dhbc").innerHTML = xhttp.responseText;
                        }
                    };
                    xhttp.open("GET", "../../ajax/asp/events/check_player_answer.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question, true);
                    xhttp.send();
                    $(".eve-team-control-send-btn").attr("disabled", "disabled");
                    $(".eve-indexof").find("#indexof-" + gamename).show();
                    $("#" + gamename).find(".eve-check-answer-btn").removeAttr("disabled");
                    $(".eve-game-time-circle-box").hide();
                    soundeffect.pause();
                },
                onUpdate: function (elapsed) {

                    $(".eve-game-time-circle-box").find(".eve-time-remain-number").html(parseInt((parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000 - Math.round(elapsed)) / 1000) + 1);
                    if ($(".eve-game-time-circle-box").find(".eve-time-remain-number").html() <= 5) {
                        $(".eve-game-time-circle-box").find(".eve-time-remain-number").addClass("nhapnhay");
                    }
                    else { $(".eve-game-time-circle-box").find(".eve-time-remain-number").removeClass("nhapnhay"); }
                },
                timeout: parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000
            }).circletimer("start");
            soundsrc = "/Content/effect/countdownclock5min.mp3";
            soundeffect.src = soundsrc;
            soundeffect.play();
        }
        else if (gamename == "tttn") {
            document.getElementById("tttn_player").innerHTML = "";
            $("#" + gamename).carousel("next");
            var level = document.getElementById("player_level").innerHTML;
            if (level == "7") {
                send_server_question(2, 1, 0, 0);
                document.getElementById("question_present_id").innerHTML = 1;
                document.getElementById("question_server_type").innerHTML = 2;
                document.getElementById("question_server_id").innerHTML = 1;
            }
            $(".eve-team-control-ring-btn").removeAttr("disabled").attr("onclick", "team_control_ring('" + gamename + "',this)");
            $(".eve-team-control-send-btn").attr("onclick", "team_control_send('" + gamename + "',this)");
            $(".eve-game-time-circle-box").show();
            $(".eve-game-time-circle").circletimer({
                onComplete: function () {
                    $("#" + gamename).find(".eve-check-answer-btn").hide();
                    $("#" + gamename).find(".eve-show-answer-btn").show();
                    $(".eve-game-time-circle-box").hide();
                    soundeffect.pause();
                    $(".eve-team-control-ring-btn").attr("disabled", "disabled");
                },
                onUpdate: function (elapsed) {
                    $(".eve-game-time-circle-box").find(".eve-time-remain-number").html(parseInt((parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000 - Math.round(elapsed)) / 1000) + 1);
                    if ($(".eve-game-time-circle-box").find(".eve-time-remain-number").html() <= 5) {
                        $(".eve-game-time-circle-box").find(".eve-time-remain-number").addClass("nhapnhay");
                    }
                    else { $(".eve-game-time-circle-box").find(".eve-time-remain-number").removeClass("nhapnhay"); }
                },
                timeout: parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000
            }).circletimer("start");
            soundsrc = "/Content/effect/countdownclock5min.mp3";
            soundeffect.src = soundsrc;
            soundeffect.play();
        }
        $("#" + gamename).find(".eve-start-game-btn").hide();
        $("#" + gamename).find(".eve-check-answer-btn").show();
    }
    else if (gamename == "gdoc") {
        $("#" + gamename).carousel("next");
        var level = document.getElementById("player_level").innerHTML;
        if (level == "7") {
            send_server_question(4, 1, 0, 0);
            document.getElementById("question_present_id").innerHTML = 1;
            document.getElementById("question_server_type").innerHTML = 4;
            document.getElementById("question_server_id").innerHTML = 1;
        }
        $(".eve-team-control-ring-btn").attr("onclick", "team_control_ring('" + gamename + "',this)");
        $(".eve-team-control-flag-btn").removeAttr("disabled").attr("onclick", "team_control_flag('" + gamename + "',this)").css("display", "inline-block");
        $(".eve-team-control-send-btn").hide();
        $(".eve-indexof").find("#indexof-" + gamename).show();
        $("#" + gamename).find(".eve-start-game-btn").hide();
        $("#" + gamename).find(".eve-main-question-btn").show();
        var r = parseInt($("#" + gamename).find(".gdoc-row").html());
        var c = parseInt($("#" + gamename).find(".gdoc-col").html());
        var k = parseInt($("#" + gamename).find(".gdoc-vertical").html());
        var tablebox = $(".gdoc-table-box");
        if (r > 0 && c > 0) {
            var innerword = document.querySelectorAll(".gdoc-value span");
            var outerword = document.querySelectorAll(".gdoc-table tr .gdoc-or");
            for (var i = 0; i < outerword.length; i++) {
                $(outerword[i]).append("<span class='w3-hide'>" + $(innerword[i]).html() + "</span>");
            }
            for (var i = 0; i < outerword.length; i++) {
                if ($(outerword[i]).find("span").html()) {
                    if ($(outerword[i]).parent().hasClass("gdoc-vertical")) {
                        $(outerword[i]).addClass("gdoc-oc gdoc-ocd");
                    }
                    else {
                        $(outerword[i]).addClass("gdoc-oc gdoc-ocn");
                    }
                }
            }
        }
    }
    else if (gamename == "xvvtlch") {
        $("#" + gamename).carousel("next");
        var level = document.getElementById("player_level").innerHTML;
        if (level == "7") {
            send_server_question(3, 1, 0, 0);
            document.getElementById("question_present_id").innerHTML = 1;
            document.getElementById("question_server_type").innerHTML = 3;
            document.getElementById("question_server_id").innerHTML = 1;
        }
        $("#" + gamename).find(".eve-start-game-btn").hide();
        $("#" + gamename).find(".eve-start-video-btn").show();
        $("#" + gamename).find(".eve-start-time-btn").show();
        $(".eve-indexof").find("#indexof-" + gamename).show();
    }
}
/*dhbc and tttn*/

function check_answer(gamename) {
    var level = document.getElementById("player_level").innerHTML;
    var rightanswer = $("#" + gamename).find(".active .eve-right-answer").html();
    var teamanswer = $("#indexof-" + gamename + " .eve-team-index .eve-team-answer-detail");
    if (gamename == "dhbc") {
        if (level == "7") {
            var event_id = document.getElementById("event_id").innerHTML;
            var check = 1;
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                }
            };
            xhttp.open("GET", "../../ajax/asp/events/check_answer.aspx?event_id=" + event_id + "&check=" + check, true);
            xhttp.send();
        }
        var checked = document.getElementById("question_checked").innerHTML;
        if (checked == "0") {
            $("#" + gamename).find(".eve-check-answer-btn").hide();
            var speed = -1;
            for (var i = 0; i < teamanswer.length; i++) {
                if ($(teamanswer[i]).html().trim() == rightanswer.trim()) {
                    speed++;
                    right_answer(teamanswer[i], speed, "dhbc");
                    if (level != "6") {
                        soundsrc = "/Content/effect/correctanswer.mp3";
                        soundeffect.src = soundsrc;
                        soundeffect.play();
                    }
                    if (level == "7") {
                        var event_id = document.getElementById("event_id").innerHTML;
                        var status = 1;
                        var xhttp;
                        xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                            if (xhttp.readyState == 4 && xhttp.status == 200) {
                            }
                        };
                        xhttp.open("GET", "../../ajax/asp/events/show_answer.aspx?event_id=" + event_id + "&status=" + status, true);
                        xhttp.send();
                    }
                }
                else {
                }
            }
            if (speed <= -1) {
                $("#" + gamename).find(".eve-show-answer-btn").show();
                if (level != "6") {
                    soundsrc = "/Content/effect/wronganswer.mp3";
                    soundeffect.src = soundsrc;
                    soundeffect.play();
                }
            }
            else {
                $("#" + gamename).find(".active .eve-right-answer").show();
                $("#" + gamename).find(".eve-next-question-btn").show();
            }
            document.getElementById("question_checked").innerHTML = 1;
        }
    }
    else if (gamename == "tttn") {
        var question_id = document.getElementById("question_server_id").innerHTML;
        if (level == "7") {
            var tttn_check = document.getElementById("tttn_check").innerHTML.trim();
            if (tttn_check == "0") {
                send_server_question(2, question_id, 0, 4);
                document.getElementById("tttn_check").innerHTML = 1;
            }
        }
        var speed = 0;
        for (var i = 0; i < teamanswer.length; i++) {
            if ($(teamanswer[i]).html().trim() == rightanswer.trim()) {
                totalanswered++;
                right_answer(teamanswer[i], speed, "tttn");
                soundsrc = "/Content/effect/correctanswer.mp3";
                soundeffect.src = soundsrc;
                soundeffect.play();
                $("#" + gamename).find(".active .eve-right-answer").show();
                $("#" + gamename).find(".eve-next-question-btn").show();
                $("#" + gamename).find(".eve-check-answer-btn").hide();
                if (level == "7")
                    send_server_question(2, question_id, 1, 0);
                //if (level == "6")
                //    send_server_question(2, question_id, 1, 0);
                document.getElementById("question_server_check").innerHTML = 0;
            }
            else {
                effectsrc = "/Content/effect/wronganswer.mp3";
                answereffect.src = effectsrc;
                answereffect.play();
                wrong_answer(teamanswer[i], "tttn");
                var notwrong = $("#indexof-" + gamename).find(".eve-team-index:not(.wronganswer)");
                for (var i = 0; i < notwrong.length; i++) {
                    if ($(".eve-team-control-box").find(".eve-team-name-hide").html() == $(notwrong[i]).find(".eve-team-name-answer").html()) {
                        $(".eve-team-control-ring-btn").removeAttr("disabled");
                    }
                }
                $(".eve-game-time-circle").circletimer("start");
                soundsrc = "/Content/effect/countdownclock5min.mp3";
                soundeffect.src = soundsrc;
                soundeffect.play();
                $("#" + gamename).find(".eve-check-answer-btn").attr("disabled", "disabled");

                if (level == "6") {
                    var player_id = document.getElementById("event_player").innerHTML;
                    var tttn_player = document.getElementById("tttn_player").innerHTML;
                    if (player_id == tttn_player) {
                        var event_id = document.getElementById("event_id").innerHTML;
                        var question_id = document.getElementById("question_server_id").innerHTML;
                        document.getElementById("question_server_check").innerHTML = "1";
                        $(".eve-team-control-ring-btn").attr("disabled", "disabled");
                        var xhttp;
                        xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                            if (xhttp.readyState == 4 && xhttp.status == 200) {
                            }
                        };
                        xhttp.open("GET", "../../ajax/asp/events/tttn_wrong.aspx?event_id=" + event_id + "&type=" + 2 + "&question_id=" + question_id, true);
                        xhttp.send();
                    }
                }
                if (level == "7") {
                    document.getElementById("indexof-tttn").innerHTML = "";
                    document.getElementById("tttn_player").innerHTML = "";
                    //var event_id = document.getElementById("event_id").innerHTML;
                    //var question_id = document.getElementById("question_server_id").innerHTML;
                    //var xhttp;
                    //xhttp = new XMLHttpRequest();
                    //xhttp.onreadystatechange = function () {
                    //    if (xhttp.readyState == 4 && xhttp.status == 200) {
                    //    }
                    //};
                    //xhttp.open("GET", "../../ajax/asp/events/tttn_wrong.aspx?event_id=" + event_id + "&type=" + 2 + "&question_id=" + question_id, true);
                    //xhttp.send();
                }
                document.getElementById("indexof-tttn").innerHTML = "";
                document.getElementById("tttn_player").innerHTML = "";
            }
        }
    }
}
function show_answer(gamename) {
    var event_id = document.getElementById("event_id").innerHTML;
    var level = document.getElementById("player_level").innerHTML;
    var status = 1;
    if (level == "7") {
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
            }
        };
        xhttp.open("GET", "../../ajax/asp/events/show_answer.aspx?event_id=" + event_id + "&status=" + status, true);
        xhttp.send();
    }
    if (gamename == "dhbc") {
        //soundsrc = "/Content/effect/showanswer.mp3";
        //soundeffect.src = soundsrc;
        //soundeffect.play();
        $("#" + gamename).find(".eve-show-answer-btn").hide();
        $("#" + gamename).find(".active .eve-right-answer").show();
        $("#" + gamename).find(".eve-next-question-btn").show();

    }
    else if (gamename == "tttn") {
        totalanswered++;
        //soundsrc = "/Content/effect/showanswer.mp3";
        //soundeffect.src = soundsrc;
        //soundeffect.play();
        $("#" + gamename).find(".eve-show-answer-btn").hide();
        $("#" + gamename).find(".active .eve-right-answer").show();
        $("#" + gamename).find(".eve-next-question-btn").show();
    }
    else if (gamename == "xvvtlch") {

        if (level == "7") {
            send_server_video(event_id, "", 3, "", "");
        }
        //soundsrc = "/Content/effect/choosehorizol.mp3";
        //soundeffect.src = soundsrc;
        //soundeffect.play();
        $("#" + gamename).find(".eve-start-video-btn").hide();
        $("#" + gamename).find(".eve-start-time-btn").hide();
        var videoanswer = $("." + gamename + " .active .xvvtlch-video");
        var srcanswer = $("." + gamename + " .active .xvvtlch-src-answer").html();
        videoanswer[0].src = srcanswer;
        videoanswer[0].play();
        videoanswer[0].addEventListener("ended", cc, false);
        function cc() {
            $("#" + gamename).find(".eve-next-question-btn").show();
        }

    }
}
function right_answer(answer, index, gamename) {
    $(answer).removeClass("w3-dark-grey").addClass("w3-green");
    $(answer).parent().parent().parent().find(".eve-team-answer-time").removeClass("w3-dark-grey").addClass("w3-green");
    var teamanswername = $(answer).parent().parent().find(".eve-team-name-answer").html();
    var teambox = $(".eve-team-list").find(".eve-team-box");
    var teamcontrolbox = $(".eve-team-control").find(".eve-team-control-box");
    var scoreindex = document.querySelectorAll("#score-" + gamename + " .eve-score-plus .eve-score-detail-box");
    for (var i = 0; i < teambox.length; i++) {
        if ($(teambox[i]).find(".eve-team-name-hide").html() == teamanswername) {
            var teamround = parseInt($(teambox[i]).find(".eve-team-round-" + gamename).html());
            var teamtotal = parseInt($(teambox[i]).find(".eve-team-total").html());
            for (var j = 0; j < scoreindex.length; j++) {
                if (index == j) {
                    teamround += parseInt($(scoreindex[j]).children().html());
                    teamtotal += parseInt($(scoreindex[j]).children().html());
                }
            }
            $(teambox[i]).find(".eve-team-round-" + gamename).html(teamround);
            $(teambox[i]).find(".eve-team-total").html(teamtotal);
        }
    }
    for (var k = 0; k < teamcontrolbox.length; k++) {
        if ($(teamcontrolbox[k]).find(".eve-team-name-hide").html() == teamanswername) {
            var teamcontrolround = parseInt($(teamcontrolbox[k]).find(".eve-team-round-" + gamename).html());
            var teamcontroltotal = parseInt($(teamcontrolbox[k]).find(".eve-team-total").html());
            var type = document.getElementById("question_server_type").innerHTML;

            for (var l = 0; l < scoreindex.length; l++) {
                if (index == l) {
                    teamcontrolround += parseInt($(scoreindex[l]).children().html());
                    teamcontroltotal += parseInt($(scoreindex[l]).children().html());
                }
            }
            $(teamcontrolbox[k]).find(".eve-team-round-" + gamename).html(teamcontrolround);
            $(teamcontrolbox[k]).find(".eve-team-total").html(teamcontroltotal);
        }
    }
}
function wrong_answer(answer, gamename) {
    $(answer).removeClass("w3-dark-grey").addClass("w3-red");
    $(answer).parent().parent().parent().find(".eve-team-answer-time").removeClass("w3-dark-grey").addClass("w3-red");
    $(answer).parent().parent().parent().addClass("wronganswer");
    var teamanswername = $(answer).parent().parent().find(".eve-team-name-answer").html();
    var teambox = $(".eve-team-list").find(".eve-team-box");
    var teamcontrolbox = $(".eve-team-control").find(".eve-team-control-box");
    var scoreindex = document.querySelector("#score-" + gamename + " .eve-score-linux .eve-score-detail-box");
    for (var i = 0; i < teambox.length; i++) {
        if ($(teambox[i]).find(".eve-team-name-hide").html() == teamanswername) {
            var teamround = parseInt($(teambox[i]).find(".eve-team-round-" + gamename).html());
            var teamtotal = parseInt($(teambox[i]).find(".eve-team-total").html());
            teamround -= parseInt($(scoreindex).children().html());
            teamtotal -= parseInt($(scoreindex).children().html());
            $(teambox[i]).find(".eve-team-round-" + gamename).html(teamround);
            $(teambox[i]).find(".eve-team-total").html(teamtotal);
        }
    }
    for (var k = 0; k < teamcontrolbox.length; k++) {
        if ($(teamcontrolbox[k]).find(".eve-team-name-hide").html() == teamanswername) {
            var teamcontrolround = parseInt($(teamcontrolbox[k]).find(".eve-team-round-" + gamename).html());
            var teamcontroltotal = parseInt($(teamcontrolbox[k]).find(".eve-team-total").html());
            teamcontrolround -= parseInt($(scoreindex).children().html());
            teamcontroltotal -= parseInt($(scoreindex).children().html());
            $(teamcontrolbox[k]).find(".eve-team-round-" + gamename).html(teamcontrolround);
            $(teamcontrolbox[k]).find(".eve-team-total").html(teamcontroltotal);
        }
    }
}
function team_control_ring(gamename, that) {
    if (gamename == "tttn") {
        var player_id = document.getElementById("event_player").innerHTML;
        var event_id = document.getElementById("event_id").innerHTML;
        var type = document.getElementById("question_server_type").innerHTML;
        var question = document.getElementById("question_server_id").innerHTML;

        var team = $(that).parent().parent().parent().find(".eve-team-name-hide").html();
        var time = parseInt($("#" + gamename).find(".eve-time-number").html()) - parseInt($(".eve-time-remain-number").html());
        var xhttp;
        $(document).ready(function () {
            $(".eve-team-control-ring-btn").attr("disabled", "disabled");
            $(".eve-game-time-circle").circletimer("pause");
            $(".eve-team-control-send-btn").removeAttr("disabled");
        });
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
            }
        };
        xhttp.open("GET", "../../ajax/asp/events/ring_tttn.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question + "&player=" + player_id, true);
        xhttp.send();
    }
    else if (gamename == "gdoc") {
        $(".eve-team-control-ring-btn").attr("disabled", "disabled");
        effectsrc = "/Content/effect/ringbell.mp3";
        answereffect.src = effectsrc;
        answereffect.play();
        var team = $(that).parent().parent().parent().find(".eve-team-name-hide").html();
        var teamindex = $("#indexof-" + gamename).find(".eve-team-index");

        //for (var i = 0; i < teamindex.length; i++) {
        //    if ($(teamindex[i]).find(".gdoc-team-name").html() == team) {
        //        $(teamindex[i]).addClass("w3-card-4 shake animated choosing").find(".gdoc-team-name").addClass("w3-white w3-text-teal");
        //        $(".eve-team-control-ring-btn").attr("disabled", "disabled");
        //    }
        //}
        var level = document.getElementById("player_level").innerHTML;
        if (level == "6") {
            var event_id = document.getElementById("event_id").innerHTML;
            var player = document.getElementById("event_player").innerHTML;
            send_ring_gdoc(event_id, player);
            $(".eve-team-index.choosing").addClass("shake animated");
        }
    }
}
function team_control_send(gamename, that) {
    if (gamename == "tttn") {
        $(".eve-team-control-ring-btn").attr("disabled", "disabled");
        document.getElementById("tttn_answered").innerHTML = 1;
        //$(".eve-team-control-send-btn").attr("disabled", "disabled");
        var answer = $(that).parent().parent().find(".eve-team-control-text").val();
        var player_id = document.getElementById("event_player").innerHTML;
        var event_id = document.getElementById("event_id").innerHTML;
        var type = document.getElementById("question_server_type").innerHTML;
        var question = document.getElementById("question_server_id").innerHTML;
        var tttn_player = document.getElementById("tttn_player").innerHTML;
        if (tttn_player == player_id) {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                }
            };
            xhttp.open("GET", "../../ajax/asp/events/send_tttn.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question + "&player=" + player_id + "&answer=" + answer, true);
            xhttp.send();
        }
        //var team = $(that).parent().parent().parent().find(".eve-team-name-hide").html();

        //$(".eve-indexof").find("#indexof-" + gamename + " .eve-team-index .eve-team-answer-detail").html(answer);

    }
    else if (gamename == "dhbc") {
        $(".eve-team-control-send-btn").attr("disabled", "disabled");
        var team = $(that).parent().parent().parent().find(".eve-team-name-hide").html();
        var time = parseInt($("#" + gamename).find(".eve-time-number").html()) - parseInt($(".eve-time-remain-number").html());
        var answer = $(that).parent().parent().find(".eve-team-control-text").val();
        var level = document.getElementById("player_level").innerHTML;
        if (level == "6") {
            var player = document.getElementById("player_id").innerHTML;
            var event_id = document.getElementById("event_id").innerHTML;
            var type = document.getElementById("question_present_type").innerHTML;
            var question = document.getElementById("question_present_id").innerHTML;
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                }
            };
            xhttp.open("GET", "../../ajax/asp/events/player_request.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question + "&player=" + player + "&request=" + answer, true);
            xhttp.send();
        }

        //$(".eve-indexof").find("#indexof-" + gamename).append("<div class='eve-team-index w3-row fadeInUp animated'>" +
        //                        "<div class='eve-team-answer-time w3-quarter w3-center w3-dark-grey'>" + time + "</div>" +
        //                        "<div class='w3-threequarter'>" +
        //                            "<div class='eve-team-name-index'>" +
        //                                "<div class='eve-team-name-answer w3-center w3-padding-4 w3-teal'>" + team + "</div>" +
        //                            "</div>" +
        //                            "<div class='eve-team-answer'>" +
        //                                "<div class='eve-team-answer-detail w3-row w3-dark-grey'>" + answer + "</div>" +
        //                            "</div>" +
        //                        "</div>" +
        //                    "</div>");
    }
}
function team_control_flag(gamename, that) {
    $(".eve-team-control-flag-btn").attr("disabled", "disabled");
    effectsrc = "/Content/effect/ringbell.mp3";
    answereffect.src = effectsrc;
    answereffect.play();
    var team = $(that).parent().parent().parent().find(".eve-team-name-hide").html();
    var teamindex = $("#indexof-" + gamename).find(".eve-team-index");
    var level = document.getElementById("player_level").innerHTML;

    if (level == "6") {
        var event_id = document.getElementById("event_id").innerHTML;
        var player = document.getElementById("event_player").innerHTML;
        var number = document.getElementsByClassName("gdoc-row")[0].innerHTML;
        var question = parseInt(number.trim()) + parseInt(1);
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("ochu_flag").innerHTML = xhttp.responseText;
            }
        };
        xhttp.open("GET", "../../ajax/asp/events/gdoc_flag.aspx?event_id=" + event_id + "&question=" + question + "&status=" + status + "&player=" + player, true);
        xhttp.send();
    }
}
/*gdoc*/
function vertical_question() {
    var level = document.getElementById("player_level").innerHTML;
    if (level == "7") {
        soundsrc = "/Content/effect/choosehorizol.mp3";
        soundeffect.src = soundsrc;
        soundeffect.play();
        var event_id = document.getElementById("event_id").innerHTML;
        var number = document.getElementsByClassName("gdoc-row")[0].innerHTML;
        send_server_gdoc(event_id, parseInt(number.trim()) + 1, 0, "", 0, 0);
    }
    $(".gdoc-number-btn").removeClass("w3-white w3-text-teal w3-card-2");
    $(".gdoc-oc").removeClass("w3-white w3-card-2 bounce flip animated");
    var delay = 0;
    var oc = document.getElementsByClassName("gdoc-oc");
    for (var i = 0; i < oc.length; i++) {
        $(oc[i]).css("animation-delay", delay + "s");
    }
    $(".gdoc-question-horizol").find(".gdoc-question-content").html("");
    $(".gdoc-question-horizol").css("transform", "translateY(100%)");
    $(".gdoc-number-btn").removeClass("opened");
    if ($(".gdoc-question-vertical").hasClass("opened")) {
        $(".eve-show-vertical-btn").hide();
        $(".gdoc-ocd").removeClass("w3-white w3-card-2 bounce animated");
        var delay = 0;
        var ocd = document.getElementsByClassName("gdoc-ocd");
        for (var i = 0; i < ocd.length; i++) {
            $(ocd[i]).css("animation-delay", delay + "s");
        }
        //$(".gdoc-question-horizol").css("transform", "translateY(100%)");
        //$(".gdoc-question-vertical").css("transform", "translateY(100%)");
        $(".gdoc-question-vertical").removeClass("opened");
    }
    else {
        if ($(".gdoc-question-vertical").hasClass("answered")) {
            $(".eve-show-vertical-btn").hide();
        }
        else {
            $(".eve-show-vertical-btn").show();
        }
        $(".gdoc-ocd").addClass("w3-white w3-card-2 bounce animated");
        var delay = 0;
        var ocd = document.getElementsByClassName("gdoc-ocd");
        for (var i = 0; i < ocd.length; i++) {
            $(ocd[i]).css("animation-delay", delay + "s");
            delay += 0.05;
        }
        //$(".gdoc-question-horizol").css("transform", "translateY(100%)");
        //$(".gdoc-question-vertical").css("transform", "translateY(0)");
        $(".gdoc-question-vertical").addClass("opened");
    }
}
function horizol_question(that, number) {
    var level = document.getElementById("player_level").innerHTML;
    if (level == "7") {
        var event_id = document.getElementById("event_id").innerHTML;
        send_server_gdoc(event_id, number.trim(), 0, "", 0, 0);
    }
    if (level == "6")
        $(".eve-team-control-ring-btn").attr("disabled", "disabled");
    soundsrc = "/Content/effect/choosehorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    $(".eve-show-vertical-btn").hide();
    $(".gdoc-ocd").removeClass("w3-white w3-card-2 bounce animated");
    var delay = 0;
    var ocd = document.getElementsByClassName("gdoc-ocd");
    for (var i = 0; i < ocd.length; i++) {
        $(ocd[i]).css("animation-delay", delay + "s");
    }
    $(".gdoc-question-horizol").css("transform", "translateY(100%)");
    $(".gdoc-question-vertical").css("transform", "translateY(100%)");
    $(".gdoc-question-vertical").removeClass("opened");
    if ($(that).hasClass("opened")) {
        $(".eve-main-question-btn").show();
        $(".eve-start-horizol-btn").hide();
        $(".eve-show-horizol-btn").hide();
        $(".eve-close-horizol-btn").hide();
        $(that).removeClass("w3-white w3-text-teal w3-card-2");
        $(that).parent().parent().find(".gdoc-oc").removeClass("w3-white w3-card-2 bounce animated");
        var delay = 0;
        var oc = $(that).parent().parent().find(".gdoc-oc");
        for (var i = 0; i < oc.length; i++) {
            $(oc[i]).css("animation-delay", delay + "s");
        }
        $(".gdoc-question-horizol").find(".gdoc-question-content").html("");
        $(".gdoc-question-horizol").css("transform", "translateY(100%)");
        $(that).removeClass("opened");
    }
    else {
        if ($(that).hasClass("answered")) {
            $(".eve-start-horizol-btn").hide();
            $(".eve-close-horizol-btn").hide();
            $(".eve-show-horizol-btn").hide();
        }
        else {
            $(".eve-start-horizol-btn").show();
            $(".eve-close-horizol-btn").show();
            $(".eve-show-horizol-btn").show();
        }
        $(".gdoc-number-btn").removeClass("opened");
        $(".eve-main-question-btn").hide();
        $(".gdoc-number-btn").removeClass("w3-white w3-text-teal w3-card-2");
        $(that).addClass("w3-white w3-text-teal w3-card-2");
        $(".gdoc-oc").removeClass("w3-white w3-card-2 bounce animated");
        $(that).parent().parent().find(".gdoc-oc").addClass("w3-white w3-card-2 bounce animated");
        var delay = 0;
        var oc = $(that).parent().parent().find(".gdoc-oc");
        for (var i = 0; i < oc.length; i++) {
            $(oc[i]).css("animation-delay", delay + "s");
            delay += 0.05;
        }
        var question = document.querySelectorAll(".gdoc-horizol-questions span");
        $(".gdoc-question-horizol").find(".gdoc-question-content").html($(question[number - 1]).html());
        $(".gdoc-question-horizol").css("transform", "translateY(0)");
        $(that).addClass("opened")
    }
}
function start_horizol(gamename) {
    var level = document.getElementById("player_level").innerHTML;
    var event_id = document.getElementById("event_id").innerHTML;
    if (level == "7") {
        send_server_gdoc(event_id, "", 3, "", "", "");
    }
    if ($(".gdoc-number-btn").hasClass("opened")) {
        var notchoosing = $("#indexof-" + gamename).find(".eve-team-index:not(.choosing)");
        $(".eve-game-time-circle-box").show();
        $(".eve-start-horizol-btn").attr("disabled", "disabled");
        $(".eve-close-horizol-btn").attr("disabled", "disabled");
        //$(".eve-show-horizol-btn").attr("disabled", "disabled");
        $(".eve-game-time-circle").circletimer({
            onComplete: function () {
                for (var i = 0; i < notchoosing.length; i++) {
                    if ($(".eve-team-control-box").find(".eve-team-name-hide").html() == $(notchoosing[i]).find(".gdoc-team-name").html()) {
                        if (document.getElementById("flag").innerHTML == "0")
                            $(".eve-team-control-ring-btn").removeAttr("disabled");
                    }
                }
                $(".eve-game-time-circle-box").hide();
                $(".eve-start-horizol-btn").removeAttr("disabled");
                $(".eve-close-horizol-btn").removeAttr("disabled");
                $(".eve-show-horizol-btn").removeAttr("disabled");
                soundeffect.pause();
            },
            onUpdate: function (elapsed) {
                $(".eve-game-time-circle-box").find(".eve-time-remain-number").html(parseInt((parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000 - Math.round(elapsed)) / 1000) + 1);
                if ($(".eve-game-time-circle-box").find(".eve-time-remain-number").html() <= 5) {
                    $(".eve-game-time-circle-box").find(".eve-time-remain-number").addClass("nhapnhay");
                }
                else { $(".eve-game-time-circle-box").find(".eve-time-remain-number").removeClass("nhapnhay"); }
            },
            timeout: parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000
        }).circletimer("start");
        soundsrc = "/Content/effect/countdownclock5min.mp3";
        soundeffect.src = soundsrc;
        soundeffect.play();
    }
}
function show_horizol() {
    var level = document.getElementById("player_level").innerHTML;
    if (level == "7") {
        var event_id = document.getElementById("event_id").innerHTML;
        send_server_gdoc(event_id, "", 1, "", 0, 0);
    }
    soundsrc = "/Content/effect/showhorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    if ($(".gdoc-number-btn").hasClass("opened")) {
        $(".gdoc-number-btn.opened").parent().parent().find(".gdoc-oc").children().removeClass("w3-hide");
        $(".gdoc-number-btn.opened").parent().parent().find(".gdoc-oc").removeClass("w3-white w3-card-2 bounce animated").addClass("flip animated");
        $(".gdoc-number-btn.opened").parent().parent().find(".gdoc-ocn").css("background", "#009688");
        $(".gdoc-number-btn.opened").parent().parent().find(".gdoc-ocd").css("background", "#ff5722");
        $(".gdoc-number-btn.opened").removeClass("w3-white w3-text-teal w3-card-2").css("background", "#009688");
        $(".gdoc-question-horizol").find(".gdoc-question-content").html("");
        $(".gdoc-question-horizol").css("transform", "translateY(100%)");
        $(".gdoc-number-btn.opened").removeClass("opened").addClass("answered");
        $(".eve-main-question-btn").show();
        $(".eve-start-horizol-btn").hide();
        $(".eve-show-horizol-btn").hide();
        $(".eve-close-horizol-btn").hide();
        if (level == "7") {
            totalanswered++;
            if (totalanswered >= totalquestion) {
                $(".eve-main-question-btn").hide();
                $(".eve-next-question-btn").show();
            }
        }
    }
}
function close_horizol() {
    var level = document.getElementById("player_level").innerHTML;
    if (level == "7") {
        var event_id = document.getElementById("event_id").innerHTML;
        send_server_gdoc(event_id, "", 2, "", 0, 0);
    }
    soundsrc = "/Content/effect/choosehorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    if ($(".gdoc-number-btn").hasClass("opened")) {
        $(".eve-main-question-btn").show();
        $(".eve-start-horizol-btn").hide();
        $(".eve-show-horizol-btn").hide();
        $(".eve-close-horizol-btn").hide();
        $(".gdoc-number-btn.opened").removeClass("w3-white w3-text-teal w3-card-2").css("background", "grey");
        $(".gdoc-number-btn.opened").parent().parent().find(".gdoc-oc").removeClass("w3-white w3-card-2 bounce animated").css("background", "grey");
        var delay = 0;
        var oc = document.getElementsByClassName("gdoc-oc");
        for (var i = 0; i < oc.length; i++) {
            $(oc[i]).css("animation-delay", delay + "s");
        }
        $(".gdoc-question-horizol").find(".gdoc-question-content").html("");
        $(".gdoc-question-horizol").css("transform", "translateY(100%)");
        $(".gdoc-number-btn.opened").removeClass("opened").addClass("audian");
    }
}
function show_vertical() {
    var level = document.getElementById("player_level").innerHTML;
    var event_id = document.getElementById("event_id").innerHTML;
    if (level == "7") {
        send_server_gdoc(event_id, "", 1, "", 0, 0);
    }
    if (level == "6")
        $(".eve-team-control-ring-btn").attr("disabled", "disabled");

    soundsrc = "/Content/effect/showhorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    if ($(".gdoc-question-vertical").hasClass("opened")) {
        $(".gdoc-table").find(".gdoc-ocd span").removeClass("w3-hide");
        $(".gdoc-table").find(".gdoc-ocd").removeClass("w3-white w3-card-2 bounce animated").addClass("flip animated");
        $(".eve-show-vertical-btn").hide();
        var delay = 0;
        var ocd = document.getElementsByClassName("gdoc-ocd");
        for (var i = 0; i < ocd.length; i++) {
            $(ocd[i]).css("animation-delay", delay + "s");
        }
        $(".gdoc-question-horizol").css("transform", "translateY(100%)");
        $(".gdoc-question-vertical").css("transform", "translateY(100%)");
        $(".gdoc-question-vertical").removeClass("opened").addClass("answered");
    }
}
function gdoc_team_answer(that) {
    var level = document.getElementById("player_level").innerHTML;
    var event_id = document.getElementById("event_id").innerHTML;
    if (level == "7") {
        var player = $(that).find(".gdoc_player_id").html();
        send_server_gdoc(event_id, "", 0, player, 0, "");
    }
    soundsrc = "/Content/effect/choosehorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    if ($(that).hasClass("choosing")) {
        $(that).removeClass("w3-card-4");
        $(that).find(".gdoc-team-name").removeClass("w3-white w3-text-teal");
        $(that).removeClass("choosing");
    }
    else {
        $(".gdoc-team-index").removeClass("fadeInUp animated").removeClass("w3-card-4");
        $(".gdoc-team-index").find(".gdoc-team-name").removeClass("w3-white w3-text-teal");
        $(".gdoc-team-index").removeClass("choosing");
        $(that).addClass("w3-card-4");
        $(that).find(".gdoc-team-name").addClass("w3-white w3-text-teal");
        $(that).addClass("choosing");
        $(".eve-team-control-ring-btn").attr("disabled", "disabled");
    }
}
function score_plus(score, gamename) {
    var level = document.getElementById("player_level").innerHTML;
    var event_id = document.getElementById("event_id").innerHTML;

    if (level == "7") {
        send_server_gdoc(event_id, "", "", "", score, "");
        $("#score-" + gamename).find(".eve-score-plus").find("input").val(0);
    }
    else {
        $("#score-gdoc").find(".eve-score-plus").find("input").val(score);
    }
    var team = $('.gdoc-team-index.choosing');
    var choosing = team.find("#gdoc_player_id").html();
    var player = document.getElementById("event_player").innerHTML;
    soundsrc = "/Content/effect/choosehorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    var who = team.find(".gdoc-team-name").html();
    var howmuch = score;
    var teambox = $(".eve-team-list").find(".eve-team-box");
    var teamcontrolbox = $(".eve-team-control").find(".eve-team-control-box");
    for (var i = 0; i < teambox.length; i++) {
        if ($(teambox[i]).find(".eve-team-name-hide").html() == who) {
            var teamround = parseInt($(teambox[i]).find(".eve-team-round-" + gamename).html());
            var teamtotal = parseInt($(teambox[i]).find(".eve-team-total").html());
            teamround += parseInt(howmuch);
            teamtotal += parseInt(howmuch);
            $(teambox[i]).find(".eve-team-round-" + gamename).html(teamround);
            $(teambox[i]).find(".eve-team-total").html(teamtotal);
        }
    }
    for (var j = 0; j < teamcontrolbox.length; j++) {
        if ($(teamcontrolbox[j]).find(".eve-team-name-hide").html() == who) {
            var teamcontrolround = parseInt($(teamcontrolbox[j]).find(".eve-team-round-" + gamename).html());
            var teamcontroltotal = parseInt($(teamcontrolbox[j]).find(".eve-team-total").html());
            teamcontrolround += parseInt(howmuch);
            teamcontroltotal += parseInt(howmuch);
            $(teamcontrolbox[j]).find(".eve-team-round-" + gamename).html(teamcontrolround);
            $(teamcontrolbox[j]).find(".eve-team-total").html(teamcontroltotal);
        }
    }
}
function score_linux(score, gamename) {
    var level = document.getElementById("player_level").innerHTML;
    var event_id = document.getElementById("event_id").innerHTML;
    if (level == "7") {
        send_server_gdoc(event_id, "", "", "", -score, "");
        $("#score-gdoc").find(".eve-score-plus").find("input").val(0);
    }
    else {
        $("#score-gdoc").find(".eve-score-plus").find("input").val(score);
    }
    var team = $('.gdoc-team-index.choosing');
    var choosing = team.find("#gdoc_player_id").html();
    var player = document.getElementById("event_player").innerHTML;
    soundsrc = "/Content/effect/choosehorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    var who = team.find(".gdoc-team-name").html();
    var howmuch = score;
    var teambox = $(".eve-team-list").find(".eve-team-box");
    var teamcontrolbox = $(".eve-team-control").find(".eve-team-control-box");
    for (var i = 0; i < teambox.length; i++) {
        if ($(teambox[i]).find(".eve-team-name-hide").html() == who) {
            var teamround = parseInt($(teambox[i]).find(".eve-team-round-" + gamename).html());
            var teamtotal = parseInt($(teambox[i]).find(".eve-team-total").html());
            teamround -= parseInt(howmuch);
            teamtotal -= parseInt(howmuch);
            $(teambox[i]).find(".eve-team-round-" + gamename).html(teamround);
            $(teambox[i]).find(".eve-team-total").html(teamtotal);
        }
    }
    for (var j = 0; j < teamcontrolbox.length; j++) {
        if ($(teamcontrolbox[j]).find(".eve-team-name-hide").html() == who) {
            var teamcontrolround = parseInt($(teamcontrolbox[j]).find(".eve-team-round-" + gamename).html());
            var teamcontroltotal = parseInt($(teamcontrolbox[j]).find(".eve-team-total").html());
            teamcontrolround -= parseInt(howmuch);
            teamcontroltotal -= parseInt(howmuch);
            $(teamcontrolbox[j]).find(".eve-team-round-" + gamename).html(teamcontrolround);
            $(teamcontrolbox[j]).find(".eve-team-total").html(teamcontroltotal);
        }
    }
}
/**/
/*xvvtlch*/
function xvvtlch_team_answer(that, gamename) {
    var event_id = document.getElementById("event_id").innerHTML;
    var level = document.getElementById("player_level").innerHTML;
    soundsrc = "/Content/effect/choosehorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    if ($(that).hasClass("choosing")) {
        $(that).removeClass("w3-card-4");
        $(that).find(".xvvtlch-team-name").removeClass("w3-white w3-text-teal");
        $(that).removeClass("choosing");
        if (level == "7") {
            var video_player = $(that).find(".xvvtlch_player_id").html();
            send_server_video(event_id, "", "", video_player, "");
            $("#" + gamename).find(".eve-start-video-btn").attr("disabled", "disabled");
        }

    }
    else {
        $(".xvvtlch-team-index").removeClass("fadeInUp animated").removeClass("w3-card-4");
        $(".xvvtlch-team-index").find(".xvvtlch-team-name").removeClass("w3-white w3-text-teal");
        $(".xvvtlch-team-index").removeClass("choosing");
        $(that).addClass("w3-card-4");
        $(that).find(".xvvtlch-team-name").addClass("w3-white w3-text-teal");
        $(that).addClass("choosing");
        if (level == "7") {
            var video_player = $(that).find(".xvvtlch_player_id").html();
            send_server_video(event_id, "", "", video_player, "");
            $("#" + gamename).find(".eve-start-video-btn").removeAttr("disabled");
        }
    }
}
function start_video(gamename) {
    var level = document.getElementById("player_level").innerHTML;
    var event_id = document.getElementById("event_id").innerHTML;
    if (level == "7") {
        send_server_video(event_id, "", 1, "", "");
    }
    soundsrc = "/Content/effect/choosehorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    var video = $("." + gamename + " .active .xvvtlch-video");
    var src = $("." + gamename + " .active .xvvtlch-src").html();
    if (video[0].paused) {
        if (video[0].src) {
            video[0].play();
        }
        else {
            video[0].src = src;
            video[0].play();
        }
    }
    else {
        video[0].pause();
    }
    video[0].addEventListener("ended", cc, false);
    function cc() {
        $("#" + gamename).find(".item.active .xvvtlch-question-content").addClass("lightSpeedIn animated").show();
        $("#" + gamename).find(".eve-start-time-btn").removeAttr("disabled");
        $("#score-" + gamename).find(".xvvtlch-betting-score").attr("disabled", "disabled");
    }
}
function start_time(gamename) {
    var level = document.getElementById("player_level").innerHTML;
    var event_id = document.getElementById("event_id").innerHTML;
    if (level == "7") {
        send_server_video(event_id, "", 2, "", "");
    }
    $("#" + gamename).find(".eve-start-video-btn").hide();
    $("#" + gamename).find(".eve-start-time-btn").hide();
    $(".eve-game-time-circle-box").show();
    $(".eve-game-time-circle").circletimer({
        onComplete: function () {
            $("#" + gamename).find(".eve-show-answer-btn").show();
            $("#score-" + gamename).find(".xvvtlch-score-btn").removeAttr("disabled");
            $(".eve-game-time-circle-box").hide();
            soundeffect.pause();
        },
        onUpdate: function (elapsed) {
            $(".eve-game-time-circle-box").find(".eve-time-remain-number").html(parseInt((parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000 - Math.round(elapsed)) / 1000) + 1);
            if ($(".eve-game-time-circle-box").find(".eve-time-remain-number").html() <= 5) {
                $(".eve-game-time-circle-box").find(".eve-time-remain-number").addClass("nhapnhay");
            }
            else { $(".eve-game-time-circle-box").find(".eve-time-remain-number").removeClass("nhapnhay"); }
        },
        timeout: parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000
    }).circletimer("start");
    soundsrc = "/Content/effect/countdownclock5min.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
}
function xvvtlch_right(gamename, score, bet) {
    var event_id = document.getElementById("event_id").innerHTML;
    var level = document.getElementById("player_level").innerHTML;
    var right_score = score;
    var betting_score = bet;
    var howmuch = parseInt(right_score) + parseInt(betting_score);
    if (level == "7") {
        send_server_video(event_id, "", "", "", howmuch);
        $("#score-" + gamename).find(".xvvtlch-betting-score").val(0);
    }
    else {
        var client_right_score = parseInt($(".xvvtlch-right-score").html());
        $("#score-" + gamename).find(".xvvtlch-betting-score").val(score - client_right_score);
    }
    var team = $('.xvvtlch-team-index.choosing');
    soundsrc = "/Content/effect/correctanswer.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    var who = team.find(".xvvtlch-team-name").html();
    var teambox = $(".eve-team-list").find(".eve-team-box");
    var teamcontrolbox = $(".eve-team-control").find(".eve-team-control-box");
    for (var i = 0; i < teambox.length; i++) {
        if ($(teambox[i]).find(".eve-team-name-hide").html() == who) {
            var teamround = parseInt($(teambox[i]).find(".eve-team-round-" + gamename).html());
            var teamtotal = parseInt($(teambox[i]).find(".eve-team-total").html());
            teamround += parseInt(howmuch);
            teamtotal += parseInt(howmuch);
            $(teambox[i]).find(".eve-team-round-" + gamename).html(teamround);
            $(teambox[i]).find(".eve-team-total").html(teamtotal);
        }
    }
    for (var j = 0; j < teamcontrolbox.length; j++) {
        if ($(teamcontrolbox[j]).find(".eve-team-name-hide").html() == who) {
            var teamcontrolround = parseInt($(teamcontrolbox[j]).find(".eve-team-round-" + gamename).html());
            var teamcontroltotal = parseInt($(teamcontrolbox[j]).find(".eve-team-total").html());
            teamcontrolround += parseInt(howmuch);
            teamcontroltotal += parseInt(howmuch);
            $(teamcontrolbox[j]).find(".eve-team-round-" + gamename).html(teamcontrolround);
            $(teamcontrolbox[j]).find(".eve-team-total").html(teamcontroltotal);
        }
    }
}
function xvvtlch_wrong(gamename, score) {
    var event_id = document.getElementById("event_id").innerHTML;
    var level = document.getElementById("player_level").innerHTML;

    if (level == "7") {
        send_server_video(event_id, "", "", "", -score);
    }
    var team = $('.xvvtlch-team-index.choosing');
    soundsrc = "/Content/effect/wronganswer.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    var who = team.find(".xvvtlch-team-name").html();
    var betting_score = score;
    var howmuch = betting_score;
    var teambox = $(".eve-team-list").find(".eve-team-box");
    var teamcontrolbox = $(".eve-team-control").find(".eve-team-control-box");
    for (var i = 0; i < teambox.length; i++) {
        if ($(teambox[i]).find(".eve-team-name-hide").html() == who) {
            var teamround = parseInt($(teambox[i]).find(".eve-team-round-" + gamename).html());
            var teamtotal = parseInt($(teambox[i]).find(".eve-team-total").html());
            teamround -= parseInt(howmuch);
            teamtotal -= parseInt(howmuch);
            $(teambox[i]).find(".eve-team-round-" + gamename).html(teamround);
            $(teambox[i]).find(".eve-team-total").html(teamtotal);
        }
    }
    for (var j = 0; j < teamcontrolbox.length; j++) {
        if ($(teamcontrolbox[j]).find(".eve-team-name-hide").html() == who) {
            var teamcontrolround = parseInt($(teamcontrolbox[j]).find(".eve-team-round-" + gamename).html());
            var teamcontroltotal = parseInt($(teamcontrolbox[j]).find(".eve-team-total").html());
            teamcontrolround -= parseInt(howmuch);
            teamcontroltotal -= parseInt(howmuch);
            $(teamcontrolbox[j]).find(".eve-team-round-" + gamename).html(teamcontrolround);
            $(teamcontrolbox[j]).find(".eve-team-total").html(teamcontroltotal);
        }
    }
}
/**/
/**/
function next_what(gamename) {
    document.getElementById("question_checked").innerHTML = 0;
    var level = document.getElementById("player_level").innerHTML;
    if (level == "7") {
        var question = document.getElementById("question_present_id").innerHTML;
        var status = 0;
        question = parseInt(question) + 1;
        document.getElementById("question_server_id").innerHTML = question;
        document.getElementById("question_present_id").innerHTML = question;
        var event_id = document.getElementById("event_id").innerHTML;
        if (gamename == "dhbc")
            send_server_question(1, question, status, 0);
        if (gamename == "tttn") {
            send_server_question(2, question, status, 0);
        }

        if (gamename == "xvvtlch")
            send_server_question(3, question, status, 0);
        if (gamename == "gdoc")
            send_server_question(4, question, status, 0);
    }
    var present_number = document.getElementById("question_server_id").innerHTML;
    var total_number = "";
    if (gamename == "dhbc")
        total_number = document.getElementById("total_dhbc").innerHTML;
    if (gamename == "tttn")
        total_number = document.getElementById("total_tttn").innerHTML;
    if (gamename == "xvvtlch")
        total_number = document.getElementById("total_video").innerHTML;
    if (gamename == "gdoc")
        total_number = document.getElementById("total_ochu").innerHTML;

    if (parseInt(present_number) > parseInt(total_number))
        end_game(gamename);
    else
        next_question(gamename);
    //totalanswered++;
    //if (gamename == "xvvtlch") {
    //    totalanswered++;
    //}
    //if (totalanswered >= totalquestion) {
    //    end_game(gamename);
    //}
    //else {
    //    next_question(gamename);
    //}
}
function next_question(gamename) {
    $("#" + gamename).carousel("next");
    if (gamename == "dhbc") {
        $("#indexof-" + gamename).html("").hide();
        $(".eve-team-control-send-btn").removeAttr("disabled");
        $(".eve-team-control-text").val("");
        $("#" + gamename).find(".eve-next-question-btn").hide();
        $("#" + gamename).find(".eve-check-answer-btn").attr("disabled", "disabled").show();
        $('.eve-game-time-circle-box').detach();
        $(".eve-time").append("<div class='eve-game-time-circle-box'>" +
                                "<div class='eve-game-time-circle'></div>" +
                                "<div class='eve-time-remain'><span class='eve-time-remain-number'></span></div>" +
                            "</div>");
        $(".eve-game-time-circle-box").show();
        $(".eve-game-time-circle").circletimer({
            onComplete: function () {
                var event_id = document.getElementById("event_id").innerHTML;
                var type = document.getElementById("question_present_type").innerHTML;
                var question = document.getElementById("question_present_id").innerHTML;
                var xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                        document.getElementById("indexof-dhbc").innerHTML = xhttp.responseText;
                    }
                };
                xhttp.open("GET", "../../ajax/asp/events/check_player_answer.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question, true);
                xhttp.send();
                $(".eve-team-control-send-btn").attr("disabled", "disabled");
                $("#indexof-" + gamename).show();
                $("#" + gamename).find(".eve-check-answer-btn").removeAttr("disabled");
                $(".eve-game-time-circle-box").hide();
                soundeffect.pause();
            },
            onUpdate: function (elapsed) {
                $(".eve-game-time-circle-box").find(".eve-time-remain-number").html(parseInt((parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000 - Math.round(elapsed)) / 1000) + 1);
                if ($(".eve-game-time-circle-box").find(".eve-time-remain-number").html() <= 5) {
                    $(".eve-game-time-circle-box").find(".eve-time-remain-number").addClass("nhapnhay");
                }
                else { $(".eve-game-time-circle-box").find(".eve-time-remain-number").removeClass("nhapnhay"); }
            },
            timeout: parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000
        }).circletimer("start");
        soundsrc = "/Content/effect/countdownclock5min.mp3";
        soundeffect.src = soundsrc;
        soundeffect.play();
    }
    else if (gamename == "tttn") {
        document.getElementById("tttn_check").innerHTML = "0";
        document.getElementById("tttn_answered").innerHTML = "0";
        document.getElementById("tttn_player").innerHTML = "";
        document.getElementById("tttn_answered_id").innerHTML = "";
        $("#indexof-" + gamename).html("");
        $("#" + gamename).find(".eve-next-question-btn").hide();
        $("#" + gamename).find(".eve-check-answer-btn").attr("disabled", "disabled").show();
        $(".eve-team-control-ring-btn").removeAttr("disabled");
        $(".eve-team-control-text").val("");
        $('.eve-game-time-circle-box').detach();
        $(".eve-time").append("<div class='eve-game-time-circle-box'>" +
                                "<div class='eve-game-time-circle'></div>" +
                                "<div class='eve-time-remain'><span class='eve-time-remain-number'></span></div>" +
                            "</div>");
        $(".eve-game-time-circle-box").show();
        $(".eve-game-time-circle").circletimer({
            onComplete: function () {
                $("#" + gamename).find(".eve-check-answer-btn").hide();
                $("#" + gamename).find(".eve-show-answer-btn").show();
                $(".eve-game-time-circle-box").hide();
                soundeffect.pause();
                $(".eve-team-control-ring-btn").attr("disabled", "disabled");

            },
            onUpdate: function (elapsed) {
                $(".eve-game-time-circle-box").find(".eve-time-remain-number").html(parseInt((parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000 - Math.round(elapsed)) / 1000) + 1);
                if ($(".eve-game-time-circle-box").find(".eve-time-remain-number").html() <= 5) {
                    $(".eve-game-time-circle-box").find(".eve-time-remain-number").addClass("nhapnhay");
                }
                else { $(".eve-game-time-circle-box").find(".eve-time-remain-number").removeClass("nhapnhay"); }
            },
            timeout: parseInt($("#" + gamename).find('.eve-time-number').html()) * 1000
        }).circletimer("start");
        soundsrc = "/Content/effect/countdownclock5min.mp3";
        soundeffect.src = soundsrc;
        soundeffect.play();
    }
    else if (gamename == "xvvtlch") {
        var level = document.getElementById("player_level").innerHTML;
        if (level == "7") {
            var event_id = document.getElementById("event_id").innerHTML;
            var type = 3;
            var question = document.getElementById("question_present_id").innerHTML;
            //question = parseInt(question) + 1;
            var status = 0;

            send_server_question(type, question, status, 0);
            send_server_video(event_id, "", 0, 0, 0);
        }
        soundsrc = "/Content/effect/choosehorizol.mp3";
        soundeffect.src = soundsrc;
        soundeffect.play();
        $(".xvvtlch-team-index").removeClass("fadeInUp animated").removeClass("w3-card-4 shake animated");
        $(".xvvtlch-team-index").find(".xvvtlch-team-name").removeClass("w3-white w3-text-teal");
        $(".xvvtlch-team-index").removeClass("choosing");
        $("#" + gamename).find(".eve-show-answer-btn").hide();
        $("#" + gamename).find(".eve-next-question-btn").hide();
        $("#score-" + gamename).find(".xvvtlch-betting-score").val(0).removeAttr("disabled");
        $("#score-" + gamename).find(".xvvtlch-score-btn").attr("disabled", "disabled");
        $("#" + gamename).find(".eve-start-video-btn").attr("disabled", "disabled").show();
        $("#" + gamename).find(".eve-start-time-btn").attr("disabled", "disabled").show();
    }
}
function end_game(gamename) {
    var level = document.getElementById("player_level").innerHTML;
    if (level == "7") {
        var event_id = document.getElementById("event_id").innerHTML;
        var number = document.getElementsByClassName("gdoc-row")[0].innerHTML;
        if (gamename == "gdoc")
            send_server_gdoc(event_id, parseInt(number.trim()) + 2, 0, "", 0, 0);
    }
    soundsrc = "/Content/effect/80percent.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();

    if (gamename == "tttn") {
        $("#tttn_end_game_list").html($("#dhbc_end_game_list").html());
    }
    if (gamename == "gdoc") {
        $("#gdoc_end_game_list").html($("#tttn_end_game_list").html());
    }
    if (gamename == "xvvtlch") {
        $("#xvvtlch_end_game_list").html($("#gdoc_end_game_list").html());
    }

    $(".eve-team-control-text").val("");
    $(".eve-team-control-ring-btn").attr("disabled", "disabled").removeAttr("onclick");
    $(".eve-team-control-flag-btn").attr("disabled", "disabled").removeAttr("onclick");
    $(".eve-team-control-send-btn").attr("disabled", "disabled").removeAttr("onclick");
    $(".eve-indexof-detail").hide();
    $(".eve-rule-detail").hide();
    $(".eve-score-detail").hide();
    $('.eve-game-time-circle-box').detach();
    $(".eve-time").append("<div class='eve-game-time-circle-box'>" +
                            "<div class='eve-game-time-circle'></div>" +
                            "<div class='eve-time-remain'><span class='eve-time-remain-number'></span></div>" +
                        "</div>");
    $("#" + gamename).find(".eve-next-question-btn").hide();
    $("#" + gamename).find(".eve-show-answer-btn").hide();
    $("#" + gamename).find(".eve-next-game-btn").show();
    $("#" + gamename).find(".eve-game-inner").hide();
    $("#" + gamename).find(".eve-end-game-report").show();
    $("#" + gamename).find(".eve-end-game-header").addClass("bounceIn animated");
    var endgameteam = $("#" + gamename + " .eve-end-game-report .eve-end-game-team");
    var teamlist = $(".eve-team-list .eve-team-box");
    var delay = 0;

    for (var i = 0; i < teamlist.length; i++) {
        if ($(teamlist[i]).find(".eve-team-name-hide").html() == $(endgameteam[i]).find(".eve-end-game-team-name-hide").html()) {
            $(endgameteam[i]).find(".eve-end-game-team-round-detail").html($(teamlist[i]).find(".eve-team-round-" + gamename).html());
            $(endgameteam[i]).find(".eve-end-game-team-total-detail").html($(teamlist[i]).find(".eve-team-total").html());
            $(endgameteam[i]).addClass("fadeInUpBig animated");
            $(endgameteam[i]).css("animation-delay", delay + "s");
            delay += 0.15;
        }
    }

    for (var i = 0; i < teamlist.length - 1; i++) {
        for (var j = i + 1; j < teamlist.length; j++) {
            if (parseInt($(teamlist[i]).find(".eve-team-total").html()) < parseInt($(teamlist[j]).find(".eve-team-total").html())) {
                var temp = $(teamlist[i]).html();
                $(teamlist[i]).html($(teamlist[j]).html());
                $(teamlist[j]).html(temp);
            }
        }
    }
    for (var i = 0; i < endgameteam.length - 1; i++) {
        for (var j = i + 1; j < endgameteam.length; j++) {
            if (parseInt($(endgameteam[i]).find(".eve-end-game-team-total-detail").html()) < parseInt($(endgameteam[j]).find(".eve-end-game-team-total-detail").html())) {
                var temp = $(endgameteam[i]).html();
                $(endgameteam[i]).html($(endgameteam[j]).html());
                $(endgameteam[j]).html(temp);
            }
        }
    }
}

function next_game(gamename) {
    var level = document.getElementById("player_level").innerHTML;
    if (level == "7") {
        var question = 0;
        var type = 0;
        var event_id = document.getElementById("event_id").innerHTML;
        if (gamename == "dhbc")
            type = 1;
        if (gamename == "tttn")
            type = 2;
        if (gamename == "xvvtlch")
            type = 3;
        if (gamename == "gdoc")
            type = 4;
        var status = 0;

        send_server_question(type, question, status, 0);
    }
    soundsrc = "/Content/effect/choosehorizol.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    totalquestion = $("#" + gamename).find(".eve-total-question").html();
    totalanswered = 0;
    $(".eve-center-header b").html($("#" + gamename).find(".eve-game-name").html());
    $(".eve-rule").find(".eve-rule-detail").hide();
    $(".eve-rule").find("#rule-" + gamename).show();
    $(".eve-score").find(".eve-score-detail").hide();
    $(".eve-score").find("#score-" + gamename).show();
    $(".eve-end-game-report").hide();
    $(".eve-game-content").hide();
    $("#" + gamename).find(".eve-next-question-btn").hide();
    $("#" + gamename).show();
}
function end_event() {
    var level = document.getElementById("player_level").innerHTML;
    var event_id = document.getElementById("event_id").innerHTML;
    if (level == "7")
        send_server_video(event_id, 1, "", "", "");
    soundsrc = "/Content/effect/80percent.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    $(".eve-left").animate({ "width": "toggle" });
    $(".eve-right").animate({ "width": "toggle" });
    $(".eve-center").animate({ "width": "100%" });
    $(".eve-game-content").hide();
    $(".eve-center-header b").html("Sự Kiện Tháng 4");
    $(".eve-team-list").clone().appendTo(".eve-end-event-result");
    $(".eve-end-event-result").find(".eve-team-list").removeClass("w3-hide").css({ "height": "100%", "overflow": "hidden" });
    var delay = 0.3;
    var teambox = $(".eve-end-event-result").find(".eve-team-list .eve-team-box");
    for (var i = 0; i < teambox.length; i++) {
        $(teambox[i]).find(".eve-team-name div").removeClass("w3-padding-4").addClass("w3-padding-8 w3-large");
        $(teambox[i]).find(".eve-team-round div").removeClass("w3-padding-4").addClass("w3-padding-8 w3-large");
        $(teambox[i]).find(".eve-team-total").css({ "padding": "32px", "font-size": "18px" });
        $(teambox[i]).css("animation-delay", delay + "s");
        delay += 0.3;
    }
    $(".eve-end-event-result").find(".eve-team-box").addClass("fadeInLeftBig animated");
    $("#endevent").show();
}
function event_winner() {
    soundsrc = "/Content/effect/100percent.mp3";
    soundeffect.src = soundsrc;
    soundeffect.play();
    effectsrc = "/Content/effect/winner.mp3";
    answereffect.src = effectsrc;
    answereffect.play();
    var list = $(".eve-end-event-result").find(".eve-team-list .eve-team-box");
    var who, max = 0;
    for (var i = 0; i < list.length; i++) {
        if (parseInt($(list[i]).find(".eve-team-total").html()) >= max) {
            max = parseInt($(list[i]).find(".eve-team-total").html());
            who = $(list[i]).find(".eve-team-name-hide").html();
        }
    }
    $(".eve-winner").html(who);
    $("#eve-winner-modal").fadeIn();
    loop();
}
$(document).ready(function () {
    $(".eve-question-slide").carousel({ interval: false, wrap: false });
    $(".eve-left").hide();
    $(".eve-rule").hide();
    $(".eve-score").hide();
    $(".eve-team").css("height", "100%");
    $(".eve-center").removeClass("w3-half").addClass("w3-threequarter");
    $(".eve-center-content").hide();
    $(window).on("beforeunload", function () {
        return "Nếu rời khỏi trang này, bạn sẽ phải chơi lại ?";
    });
});
function send_server_question(type, question, status, check) {
    var event = document.getElementById("event_id").innerHTML;

    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
        }
    };
    xhttp.open("GET", "../../ajax/asp/events/event_details.aspx?id=" + event + "&type=" + type + "&question=" + question + "&status=" + status + "&check=" + check, true);
    xhttp.send();
}

function open_event() {
    var status = document.getElementById("event_status").innerHTML.trim();
    if (status != "1") {
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("event_status").innerHTML = 1;
            }
        };
        xhttp.open("GET", "../../ajax/asp/events/open_event.aspx", true);
        xhttp.send();
    }
}

function open_question() {
    var question = document.getElementById("question_status").innerHTML;
    if (question == 1) {
        var type = document.getElementById("question_present_type").innerHTML;
        if (type == 1)
            start_question("dhbc");
        if (type == 2)
            start_question("tttn");
        if (type == 3)
            start_question("xvvtlch");
        if (type == 4)
            start_question("gdoc");
        document.getElementById("question_loaded").innerHTML = 2;
    }
    if (question == 0) {
        var event = document.getElementById("event_id").innerHTML;
        var type = document.getElementById("question_present_type").innerHTML;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                var check = xhttp.responseText.trim();
                document.getElementById("question_status").innerHTML = check.trim();
                document.getElementById("question_status").innerHTML = document.getElementById("question_status").innerHTML.trim();

            }
        };
        xhttp.open("GET", "../../ajax/asp/events/check_question_status.aspx?id=" + event + "&type=" + type, true);
        xhttp.send();
    }
}

function check_event() {
    var event = document.getElementById("event_id").innerHTML;
    var status = document.getElementById("event_status").innerHTML;
    if (status != 1) {
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                var check = xhttp.responseText.trim();
                document.getElementById("event_status").innerHTML = check.trim();
                document.getElementById("event_status").innerHTML = document.getElementById("event_status").innerHTML.trim();
            }
        };
        xhttp.open("GET", "../../ajax/asp/events/check_event_status.aspx?id=" + event, true);
        xhttp.send();
    }
}

setInterval(function () { player_load() }, "100");
function player_load() {
    var level = document.getElementById("player_level").innerHTML;
    var type = document.getElementById("question_server_type").innerHTML;
    if (type == "2") {
        $(".eve-indexof").find("#indexof-tttn").show();
        $(".eve-indexof").find("#indexof-dhbc").hide();
        $(".eve-indexof").find("#indexof-gdoc").hide();
        $(".eve-indexof").find("#indexof-xvvtlch").hide();
        check_tttn_player();
    }

    if (type == "3") {
        $(".eve-indexof").find("#indexof-tttn").hide();
        $(".eve-indexof").find("#indexof-dhbc").hide();
        $(".eve-indexof").find("#indexof-gdoc").hide();
        $(".eve-indexof").find("#indexof-xvvtlch").show();
        if (level == "6")
            check_video();
    }
    if (type == "4") {
        $(".eve-indexof").find("#indexof-tttn").hide();
        $(".eve-indexof").find("#indexof-dhbc").hide();
        $(".eve-indexof").find("#indexof-gdoc").show();
        $(".eve-indexof").find("#indexof-xvvtlch").hide();

        if (level == "6")
            check_ochu();
        if (level == "7")
            check_ring();
    }

    if (level == 6) {
        check_event();
        var status = document.getElementById("event_status").innerHTML;
        if (status == "1") {
            //var type = document.getElementById("question_server_type").innerHTML;
            //if (type != "0") {
            check_server_game();
            //}
        }
    }
}
function check_server_game() {
    var event_id = document.getElementById("event_id").innerHTML;
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("server_request").innerHTML = xhttp.responseText;
            check_game_type();
            check_game_id();
            check_game_status();
            check_game_check();
        }
    };
    xhttp.open("GET", "../../ajax/asp/events/check_server_game.aspx?event_id=" + event_id, true);
    xhttp.send();
}
function check_game_type() {
    var level = document.getElementById("player_level").innerHTML;
    if (level == 6) {
        check_event();
        var status = document.getElementById("event_status").innerHTML;
        if (status == "1") {
            var present_type = document.getElementById("question_present_type").innerHTML;
            var server_type = document.getElementById("question_server_type").innerHTML;
            if (present_type != server_type) {
                document.getElementById("question_present_type").innerHTML = server_type;
                document.getElementById("question_present_id").innerHTML = 0;
                document.getElementById("question_server_id").innerHTML = 0;
                if (server_type == "1")
                    start_game("dhbc");
                if (server_type == '2')
                    next_game("tttn");
                if (server_type == '3') {
                    next_game("xvvtlch");
                }
                if (server_type == '4')
                    next_game("gdoc");
            }
        }
    }
}

function check_game_id() {
    var present_id = document.getElementById("question_present_id").innerHTML;
    var server_id = document.getElementById("question_server_id").innerHTML;
    var server_type = document.getElementById("question_server_type").innerHTML;
    if (present_id != server_id) {
        if (present_id == "0") {
            if (server_type == "1")
                start_question("dhbc");
            if (server_type == "2")
                start_question("tttn");
            if (server_type == "3")
                start_question("xvvtlch");
            if (server_type == "4")
                start_question("gdoc");
        }
        else {
            if (server_type == "1")
                next_what("dhbc");
            if (server_type == "2")
                next_what("tttn");
            if (server_type == "3")
                next_what("xvvtlch");
            if (server_type == "4")
                next_what("gdoc");
        }

        document.getElementById("question_present_id").innerHTML = parseInt(present_id) + 1;
    }
}

function check_game_status() {
    var status = document.getElementById("question_server_status").innerHTML;
    var server_type = document.getElementById("question_server_type").innerHTML;
    if (status == "1") {
        if (server_type == "1") {
            show_answer("dhbc");
        }
        if (server_type == "2") {
            show_answer("tttn");
        }
        if (server_type == "4") {
            show_answer("gdoc");
        }
    }

}

function check_game_check() {
    var event_id = document.getElementById("event_id").innerHTML;
    var level = document.getElementById("player_level").innerHTML;
    var check = document.getElementById("question_server_check").innerHTML;
    var server_type = document.getElementById("question_server_type").innerHTML;
    if (check == "1") {
        if (server_type == "1") {
            check_answer("dhbc");
        }
        if (server_type == "3") {
            check_answer("xvvtlch");
        }
        if (server_type == "4") {
            check_answer("gdoc");
        }
    }

}
function check_tttn_player() {
    var level = document.getElementById("player_level").innerHTML;

    if (level == "6") {
        var check = document.getElementById("question_server_check").innerHTML;
        if (check == "1") {
            var tttn_answered = document.getElementById("tttn_answered").innerHTML;
            if (tttn_answered.trim() == "0") {
                //$(".eve-game-time-circle").circletimer("start");
                //soundeffect.play();
                $(".eve-team-control-ring-btn").removeAttr("disabled");
            }
        }
        if (check == "2") {

            $(".eve-game-time-circle").circletimer("pause");
            soundeffect.pause();
            var event_id = document.getElementById("event_id").innerHTML;
            var tttn_player = document.getElementById("tttn_player").innerHTML;
            var question_id = document.getElementById("question_server_id").innerHTML;
            var type = document.getElementById("question_server_type").innerHTML;
            var player_id = document.getElementById("event_player").innerHTML;
            var tttn_player_new = "";
            if (tttn_player == "") {
                var xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                        document.getElementById("tttn_request").innerHTML = xhttp.responseText;
                    }
                };
                xhttp.open("GET", "../../ajax/asp/events/check_game_tttn.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question_id, true);
                xhttp.send();
            }
            else {
                if (tttn_player.trim() != player_id.trim()) {
                    $(document).ready(function () {
                        $(".eve-team-control-ring-btn").attr("disabled", "disabled");
                        $(".eve-team-control-send-btn").attr("disabled", "disabled");
                    });
                }
                else {
                    $(document).ready(function () {
                        $(".eve-team-control-ring-btn").attr("disabled", "disabled");
                        $(".eve-team-control-send-btn").removeAttr("disabled");
                    });
                }

                var xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                        document.getElementById("indexof-tttn").innerHTML = xhttp.responseText;
                        $(".eve-indexof").find("#indexof-tttn").show();
                    }
                };
                xhttp.open("GET", "../../ajax/asp/events/show_tttn.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question_id, true);
                xhttp.send();
            }
        }
        if (check == "3") {
            $(".eve-team-control-ring-btn").attr("disabled", "disabled");
            $(".eve-team-control-send-btn").attr("disabled", "disabled");
        }
        var client_check = document.getElementById("question_client_check").innerHTML;
        if (check != client_check) {
            document.getElementById("question_client_check").innerHTML = check;
            client_check = document.getElementById("question_client_check").innerHTML;
            if (client_check == "4")
                check_answer("tttn");
        }
    }
    if (level == "7") {
        var event_id = document.getElementById("event_id").innerHTML;
        var tttn_player = document.getElementById("tttn_player").innerHTML;
        var question_id = document.getElementById("question_server_id").innerHTML;
        var type = document.getElementById("question_server_type").innerHTML;
        var check = document.getElementById("indexof-tttn").innerHTML;
        var tttn_answered_id = document.getElementById("tttn_answered_id").innerHTML.trim();
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("tttn_request").innerHTML = xhttp.responseText;
                var tttn_request_new = document.getElementById("tttn_player").innerHTML.trim();

                if (tttn_request_new != "" && tttn_request_new != tttn_answered_id) {
                    $(".eve-game-time-circle").circletimer("pause");
                    soundeffect.pause();
                    soundsrc = "/Content/effect/ringbell.mp3";
                    soundeffect.src = soundsrc;
                    soundeffect.play();
                    document.getElementById("tttn_check").innerHTML = "0";
                    document.getElementById("tttn_answered_id").innerHTML = tttn_request_new;
                    var xhttp2;
                    xhttp2 = new XMLHttpRequest();
                    xhttp2.onreadystatechange = function () {
                        if (xhttp2.readyState == 4 && xhttp2.status == 200) {
                            document.getElementById("indexof-tttn").innerHTML = xhttp2.responseText;
                            $(".eve-indexof").find("#indexof-tttn").show();
                            $("#tttn").find(".eve-check-answer-btn").removeAttr("disabled");
                        }
                    };
                    xhttp2.open("GET", "../../ajax/asp/events/show_tttn.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question_id, true);
                    xhttp2.send();
                }
                else {
                    var xhttp2;
                    xhttp2 = new XMLHttpRequest();
                    xhttp2.onreadystatechange = function () {
                        if (xhttp2.readyState == 4 && xhttp2.status == 200) {
                            document.getElementById("indexof-tttn").innerHTML = xhttp2.responseText;
                            $(".eve-indexof").find("#indexof-tttn").show();
                            if (document.getElementById("indexof-tttn").innerHTML.trim() == "") {
                                $("#tttn").find(".eve-check-answer-btn").attr("disabled", "disabled");
                            } else {
                                $("#tttn").find(".eve-check-answer-btn").removeAttr("disabled");
                            }
                        }
                    };
                    xhttp2.open("GET", "../../ajax/asp/events/show_tttn.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question_id, true);
                    xhttp2.send();
                }
            }
        };
        xhttp.open("GET", "../../ajax/asp/events/check_game_tttn.aspx?event_id=" + event_id + "&type=" + type + "&question=" + question_id, true);
        xhttp.send();
    }
}

function check_ochu() {

    var event_id = document.getElementById("event_id").innerHTML;
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("ochu_server").innerHTML = xhttp.responseText;
        }
    };
    xhttp.open("GET", "../../ajax/asp/events/check_game_gdoc.aspx?event_id=" + event_id, true);
    xhttp.send();

    var server_question = document.getElementById("ochu_server_question").innerHTML;
    var server_status = document.getElementById("ochu_server_status").innerHTML;
    var server_player = document.getElementById("ochu_server_player").innerHTML;
    var server_score = document.getElementById("ochu_server_score").innerHTML;
    var server_ring = document.getElementById("ochu_server_ring").innerHTML;

    var client_question = document.getElementById("ochu_client_question").innerHTML;
    var client_status = document.getElementById("ochu_client_status").innerHTML;
    var client_player = document.getElementById("ochu_client_player").innerHTML;
    var client_score = document.getElementById("ochu_client_score").innerHTML;
    var client_ring = document.getElementById("ochu_client_ring").innerHTML;

    if (server_question != client_question) {
        document.getElementById("ochu_check_question").innerHTML = 1;
    }
    if (server_status != client_status) {
        document.getElementById("ochu_check_status").innerHTML = 1;
    }
    if (server_player != client_player) {
        document.getElementById("ochu_check_player").innerHTML = 1;
    }
    if (server_score != client_score) {
        document.getElementById("ochu_check_score").innerHTML = 1;
    }
    if (server_ring != client_ring) {
        document.getElementById("ochu_check_ring").innerHTML = 1;
    }

    var check_question = document.getElementById("ochu_check_question").innerHTML;
    var check_status = document.getElementById("ochu_check_status").innerHTML;
    var check_player = document.getElementById("ochu_check_player").innerHTML;
    var check_score = document.getElementById("ochu_check_score").innerHTML;
    var check_ring = document.getElementById("ochu_check_ring").innerHTML;

    if (check_player == "1") {
        document.getElementById("ochu_client_player").innerHTML = server_player;
        client_player = document.getElementById("ochu_client_player").innerHTML;
        gdoc_team_answer("#gdoc_" + client_player);
        document.getElementById("ochu_check_player").innerHTML = "0";
    }
    if (check_question == "1") {
        document.getElementById("ochu_client_question").innerHTML = server_question;
        client_question = document.getElementById("ochu_client_question").innerHTML;
        if (client_question > 0) {
            var gdoc_row = document.getElementsByClassName("gdoc-row")[0].innerHTML;
            if (parseInt(client_question) <= parseInt(gdoc_row.trim())) {
                if (document.getElementById("flag").innerHTML == "0")
                    $(".eve-team-control-flag-btn").removeAttr("disabled");
                horizol_question("#gdoc_number_" + client_question, client_question);
            }
            else {
                if (parseInt(client_question) == parseInt(gdoc_row.trim()) + 1) {
                    vertical_question();
                    $(".eve-team-control-flag-btn").attr("disabled", "disabled");
                }
                else {
                    if (parseInt(client_question) >= parseInt(gdoc_row.trim()) + 2)
                        end_game("gdoc");
                }
            }

        }
        document.getElementById("ochu_check_question").innerHTML = "0";
    }
    if (check_status == "1") {
        document.getElementById("ochu_client_status").innerHTML = server_status;
        client_question = document.getElementById("ochu_client_question").innerHTML;
        var gdoc_row = document.getElementsByClassName("gdoc-row")[0].innerHTML;
        client_status = document.getElementById("ochu_client_status").innerHTML;
        if (client_status == "1") //mở đáp án
        {
            if (parseInt(client_question) > parseInt(gdoc_row.trim()))
                show_vertical();
            else
                show_horizol();
        }
        if (client_status == "2") { //đóng đáp án
            if (parseInt(client_question) <= parseInt(gdoc_row.trim()) && parseInt(client_question) > 0)
                close_horizol();
        }
        if (client_status == "3") { //tính giờ
            start_horizol('gdoc');
        }
        document.getElementById("ochu_check_status").innerHTML = "0";
    }
    if (check_score == "1") {
        document.getElementById("ochu_client_score").innerHTML = server_score;
        client_score = document.getElementById("ochu_client_score").innerHTML;
        if (client_score > 0)
            score_plus(client_score, 'gdoc');
        else
            score_linux(parseInt(client_score) * (-1), 'gdoc');
        document.getElementById("ochu_check_score").innerHTML = "0";
    }
    if (check_ring == "1") {
        document.getElementById("ochu_client_ring").innerHTML = server_ring;
        document.getElementById("ochu_check_ring").innerHTML = "0";
    }
}

function send_server_gdoc(event_id, question, status, player, score, ring) {
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
        }
    };
    xhttp.open("GET", "../../ajax/asp/events/send_server_gdoc.aspx?event_id=" + event_id + "&question=" + question + "&status=" + status + "&player=" + player + "&score=" + score + "&ring=" + ring, true);
    xhttp.send();
}

function send_ring_gdoc(event_id, player) {
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
        }
    };
    xhttp.open("GET", "../../ajax/asp/events/ring_gdoc.aspx?event_id=" + event_id + "&player=" + player, true);
    xhttp.send();
}

function check_ring() {
    var event_id = document.getElementById("event_id").innerHTML;
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("ochu_server_ring").innerHTML = xhttp.responseText;
            var server_ring = document.getElementById("ochu_server_ring").innerHTML.trim();
            var ring = document.getElementById("ochu_ring").innerHTML.trim();

            if (server_ring.trim() != ring.trim()) {
                document.getElementById("ochu_ring").innerHTML = server_ring.trim();
                ring = document.getElementById("ochu_ring").innerHTML.trim();
                if (ring.trim() != "0")
                    gdoc_team_answer("#gdoc_" + ring);
            }
        }
    };
    xhttp.open("GET", "../../ajax/asp/events/gdoc_check_ring.aspx?event_id=" + event_id, true);
    xhttp.send();
}

function check_video() {
    var event_id = document.getElementById("event_id").innerHTML;
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("video_server").innerHTML = xhttp.responseText;
        }
    };
    xhttp.open("GET", "../../ajax/asp/events/check_game_video.aspx?event_id=" + event_id, true);
    xhttp.send();

    var server_question = document.getElementById("video_server_question").innerHTML;
    var server_status = document.getElementById("video_server_status").innerHTML;
    var server_player = document.getElementById("video_server_player").innerHTML;
    var server_score = document.getElementById("video_server_score").innerHTML;

    var client_question = document.getElementById("video_client_question").innerHTML;
    var client_status = document.getElementById("video_client_status").innerHTML;
    var client_player = document.getElementById("video_client_player").innerHTML;
    var client_score = document.getElementById("video_client_score").innerHTML;

    if (server_question != client_question) {
        document.getElementById("video_check_question").innerHTML = 1;
    }
    if (server_status != client_status) {
        document.getElementById("video_check_status").innerHTML = 1;
    }
    if (server_player != client_player) {
        document.getElementById("video_check_player").innerHTML = 1;
    }
    if (server_score != client_score) {
        document.getElementById("video_check_score").innerHTML = 1;
    }

    var check_question = document.getElementById("video_check_question").innerHTML;
    var check_status = document.getElementById("video_check_status").innerHTML;
    var check_player = document.getElementById("video_check_player").innerHTML;
    var check_score = document.getElementById("video_check_score").innerHTML;

    if (check_question == "1") {
        document.getElementById("video_client_question").innerHTML = server_question;
        client_question = document.getElementById("video_client_question").innerHTML;

        if (client_question == "1")
            end_event();
        document.getElementById("video_check_question").innerHTML = 0;
    }
    if (check_status == "1") {
        document.getElementById("video_client_status").innerHTML = server_status;
        client_status = document.getElementById("video_client_status").innerHTML.trim();
        if (client_status != "0") {
            if (client_status == "1")
                start_video("xvvtlch");
            if (client_status == "2")
                start_time("xvvtlch");
            if (client_status == "3")
                show_answer("xvvtlch");
        }
        document.getElementById("video_check_status").innerHTML = 0;
    }
    if (check_player == "1") {
        document.getElementById("video_client_player").innerHTML = server_player;
        client_player = document.getElementById("video_client_player").innerHTML.trim();
        xvvtlch_team_answer("#xvvtlch_" + client_player, 'xvvtlch');
        document.getElementById("video_check_player").innerHTML = 0;
    }
    if (check_score == "1") {
        document.getElementById("video_client_score").innerHTML = server_score;
        video_score = document.getElementById("video_client_score").innerHTML;
        if (video_score > 0)
            xvvtlch_right('xvvtlch', video_score, 0);
        else
            xvvtlch_wrong('xvvtlch', parseInt(video_score) * (-1));

        document.getElementById("video_check_score").innerHTML = "0";
    }
}

function send_server_video(event_id, question, status, player, score) {
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
        }
    };
    xhttp.open("GET", "../../ajax/asp/events/send_server_video.aspx?event_id=" + event_id + "&question=" + question + "&status=" + status + "&player=" + player + "&score=" + score, true);
    xhttp.send();
}
